var router = require('koa-router')();
const usersModel = require('../models/users');

router.prefix('/users');

router.post('/register', async (ctx) => {
    const { login_name, passwd } = ctx.request.body;
    ctx.body = usersModel.registerUser(login_name, passwd);
});

router.post('/login', async (ctx) => {
  const { login_name, passwd } = ctx.request.body;
  console.log('Login attempt:', login_name, passwd); // 添加调试信息
  ctx.body = usersModel.authenticateUser(login_name, passwd);
});

router.get('/', function *(next) {
    this.body = 'this is a users response!';
});

router.get('/bar', function *(next) {
    this.body = 'this is a users/bar response!';
});

module.exports = router;
